home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_perl.idb / usr / freeware / catman / u_man / cat1 / a2p.Z / a2p
Encoding:
Text File  |  1998-10-28  |  8.4 KB  |  265 lines

  1.  
  2.  
  3.  
  4.      AAAA2222PPPP((((1111))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        AAAA2222PPPP((((1111))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       a2p -    Awk to Perl translator
  10.  
  11.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.       aaaa2222pppp [[[[ooooppppttttiiiioooonnnnssss]]]]    ffffiiiilllleeeennnnaaaammmmeeee
  13.  
  14.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  15.       _A_2_p takes an awk script specified on the command line    (or
  16.       from standard    input) and produces a comparable _p_e_r_l script
  17.       on the standard output.
  18.  
  19.       OOOOppppttttiiiioooonnnnssss
  20.  
  21.       Options include:
  22.  
  23.       ----DDDD<<<<nnnnuuuummmmbbbbeeeerrrr>>>>
  24.            sets debugging flags.
  25.  
  26.       ----FFFF<<<<cccchhhhaaaarrrraaaacccctttteeeerrrr>>>>
  27.            tells a2p that this awk script is always    invoked    with
  28.            this ----FFFF switch.
  29.  
  30.       ----nnnn<<<<ffffiiiieeeellllddddlllliiiisssstttt>>>>
  31.            specifies the names of the input    fields if input    does
  32.            not have    to be split into an array.  If you were
  33.            translating an awk script that processes    the password
  34.            file, you might say:
  35.  
  36.                a2p -7 -nlogin.password.uid.gid.gcos.shell.home
  37.  
  38.            Any delimiter can be used to separate the field names.
  39.  
  40.       ----<<<<nnnnuuuummmmbbbbeeeerrrr>>>>
  41.            causes a2p to assume that input will always have    that
  42.            many fields.
  43.  
  44.       ----oooo   tells a2p to use    old awk    behavior.  For now, the    only
  45.            difference is that old awk always has a line loop, even
  46.            if there    are no line actions, whereas new awk does not.
  47.  
  48.       """"CCCCoooonnnnssssiiiiddddeeeerrrraaaattttiiiioooonnnnssss""""
  49.  
  50.       A2p cannot do    as good    a job translating as a human would,
  51.       but it usually does pretty well.  There are some areas where
  52.       you may want to examine the perl script produced and tweak
  53.       it some.  Here are some of them, in no particular order.
  54.  
  55.       There    is an awk idiom    of putting _i_n_t() around    a string
  56.       expression to    force numeric interpretation, even though the
  57.       argument is always integer anyway.  This is generally
  58.       unneeded in perl, but    a2p can't tell if the argument is
  59.       always going to be integer, so it leaves it in.  You may
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 10/23/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      AAAA2222PPPP((((1111))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        AAAA2222PPPP((((1111))))
  71.  
  72.  
  73.  
  74.       wish to remove it.
  75.  
  76.       Perl differentiates numeric comparison from string
  77.       comparison.  Awk has one operator for    both that decides at
  78.       run time which comparison to do.  A2p    does not try to    do a
  79.       complete job of awk emulation    at this    point.    Instead    it
  80.       guesses which    one you    want.  It's almost always right, but
  81.       it can be spoofed.  All such guesses are marked with the
  82.       comment "#???".  You should go through and check them.  You
  83.       might    want to    run at least once with the ----wwww switch to    perl,
  84.       which    will warn you if you use == where you should have used
  85.       eq.
  86.  
  87.       Perl does not    attempt    to emulate the behavior    of awk in
  88.       which    nonexistent array elements spring into existence
  89.       simply by being referenced.  If somehow you are relying on
  90.       this mechanism to create null    entries    for a subsequent
  91.       for...in, they won't be there    in perl.
  92.  
  93.       If a2p makes a split line that assigns to a list of
  94.       variables that looks like (Fld1, Fld2, Fld3...) you may want
  95.       to rerun a2p using the ----nnnn option mentioned above.  This will
  96.       let you name the fields throughout the script.  If it    splits
  97.       to an    array instead, the script is probably referring    to the
  98.       number of fields somewhere.
  99.  
  100.       The exit statement in    awk doesn't necessarily    exit; it goes
  101.       to the END block if there is one.  Awk scripts that do
  102.       contortions within the END block to bypass the block under
  103.       such circumstances can be simplified by removing the
  104.       conditional in the END block and just    exiting    directly from
  105.       the perl script.
  106.  
  107.       Perl has two kinds of    array, numerically-indexed and
  108.       associative.    Perl associative arrays    are called "hashes".
  109.       Awk arrays are usually translated to hashes, but if you
  110.       happen to know that the index    is always going    to be numeric
  111.       you could change the {...} to    [...].    Iteration over a hash
  112.       is done using    the _k_e_y_s() function, but iteration over    an
  113.       array    is NOT.     You might need    to modify any loop that
  114.       iterates over    such an    array.
  115.  
  116.       Awk starts by    assuming OFMT has the value %.6g.  Perl    starts
  117.       by assuming its equivalent, $#, to have the value %.20g.
  118.       You'll want to set $#    explicitly if you use the default
  119.       value    of OFMT.
  120.  
  121.       Near the top of the line loop    will be    the split operation
  122.       that is implicit in the awk script.  There are times when
  123.       you can move this down past some conditionals    that test the
  124.       entire record    so that    the split is not done as often.
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 10/23/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      AAAA2222PPPP((((1111))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        AAAA2222PPPP((((1111))))
  137.  
  138.  
  139.  
  140.       For aesthetic    reasons    you may    wish to    change the array base
  141.       $[ from 1 back to perl's default of 0, but remember to
  142.       change all array subscripts AND all _s_u_b_s_t_r() and _i_n_d_e_x()
  143.       operations to    match.
  144.  
  145.       Cute comments    that say "# Here is a workaround because awk
  146.       is dumb" are passed through unmodified.
  147.  
  148.       Awk scripts are often    embedded in a shell script that    pipes
  149.       stuff    into and out of    awk.  Often the    shell script wrapper
  150.       can be incorporated into the perl script, since perl can
  151.       start    up pipes into and out of itself, and can do other
  152.       things that awk can't    do by itself.
  153.  
  154.       Scripts that refer to    the special variables RSTART and
  155.       RLENGTH can often be simplified by referring to the
  156.       variables $`,    $& and $', as long as they are within the
  157.       scope    of the pattern match that sets them.
  158.  
  159.       The produced perl script may have subroutines    defined    to
  160.       deal with awk's semantics regarding getline and print.
  161.       Since    a2p usually picks correctness over efficiency.    it is
  162.       almost always    possible to rewrite such code to be more
  163.       efficient by discarding the semantic sugar.
  164.  
  165.       For efficiency, you may wish to remove the keyword from any
  166.       return statement that    is the last statement executed in a
  167.       subroutine.  A2p catches the most common case, but doesn't
  168.       analyze embedded blocks for subtler cases.
  169.  
  170.       ARGV[0] translates to    $ARGV0,    but ARGV[n] translates to
  171.       $ARGV[$n].  A    loop that tries    to iterate over    ARGV[0]    won't
  172.       find it.
  173.  
  174.      EEEENNNNVVVVIIIIRRRROOOONNNNMMMMEEEENNNNTTTT
  175.       A2p uses no environment variables.
  176.  
  177.      AAAAUUUUTTTTHHHHOOOORRRR
  178.       Larry    Wall <_l_a_r_r_y@_w_a_l_l._o_r_g>
  179.  
  180.      FFFFIIIILLLLEEEESSSS
  181.      SSSSEEEEEEEE AAAALLLLSSSSOOOO
  182.        perl      The perl compiler/interpreter
  183.  
  184.        s2p      sed to perl translator
  185.  
  186.  
  187.      DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  188.      BBBBUUUUGGGGSSSS
  189.       It would be possible to emulate awk's    behavior in selecting
  190.       string versus    numeric    operations at run time by inspection
  191.       of the operands, but it would    be gross and inefficient.
  192.  
  193.  
  194.  
  195.      Page 3                        (printed 10/23/98)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      AAAA2222PPPP((((1111))))         22223333////JJJJuuuullll////99998888 ((((ppppeeeerrrrllll 5555....000000005555,,,, ppppaaaattttcccchhhh 00002222))))        AAAA2222PPPP((((1111))))
  203.  
  204.  
  205.  
  206.       Besides, a2p almost always guesses right.
  207.  
  208.       Storage for the awk syntax tree is currently static, and can
  209.       run out.
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                        (printed 10/23/98)
  262.  
  263.  
  264.  
  265.